package com.ruoyi.web.controller.orderview;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.orderview.mapper.ReturnNumMapper;
import com.ruoyi.orderview.service.ReturnThing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Author 程家伟
 * Date 2022/1/21 8:48
 * Email 3497357686@qq.com
 */

@RestController
public class OrderViewController {
    @Autowired
    private ReturnThing returnThing;


    @GetMapping("/orderview")
  //  @PreAuthorize("@ss.hasPermi('labormgr:labor:list')")
    public AjaxResult orderView(String start, String end, Integer type){
        Date startTime = new Date();
        Date endTime = new Date();
        try {
            startTime = new SimpleDateFormat("yyyy-MM-dd").parse(start);
            endTime = new SimpleDateFormat("yyyy-MM-dd").parse(end);
        } catch (ParseException e) {
            e.printStackTrace();
            return AjaxResult.error("请输入正确的日期");
        }
        AjaxResult ajax = AjaxResult.success();
        List<String> dateList = returnThing.getDateList(startTime, endTime);
        List<Integer> numList = returnThing.getNumList(startTime,endTime, type);
        HashMap<String, List> map = new HashMap<>();
        dateList.remove(dateList.size()-1);
        map.put("dateList",dateList);
        map.put("number",numList);

        ajax.put("data",map);
        ajax.put("list",returnThing.getReturnNumList(dateList,numList));
        ajax.put("total",returnThing.getTotal(startTime,endTime));
       return ajax;
    }
}
